package com.cl.pattern.strategy.context2;

import com.cl.pattern.strategy.*;

/**
 * 上下文
 *
 * context与简单工厂模式结合
 * 选择策略的逻辑交给客户端，避免了if else判断
 * @Description
 * @Author Small
 * @Date 2020/6/2 18:17
 * @Version 1.0
 **/
public class Context2 {
    private PayStrategy payment;

    public Context2(PayTypeEnum pay) {
        switch (pay){
            case ALI:
                payment = new AliPay();
                break;
            case JD:
                payment = new JDPay();
                break;
            case WX:
                payment = new WxPay();
                break;
            case BAIDU:
                payment = new BaiduPay();
                break;
            default:
                break;
        }
    }

    public void executePay() {
        payment.pay();
    }
}
